/*********************\
* Author:Dzlua
* QQ:505544956
* Time:2017/04/16
\**********************/
#include "LuaMenu.h"

#define CObjPtr ((CMenuUI*)m_cobj)

namespace DuiLib {

int LuaMenu::Add(LuaState *L)
{
    LuaStack args(L);
    bool bRet = false;
    CControlUI* ctrl = (CControlUI*)LuaHelperNS::GetCObjectData(args[2]);
    bRet = CObjPtr->Add(ctrl);
    L->PushBoolean(bRet);
    return 1;
}

int LuaMenu::AddAt(LuaState *L)
{
    LuaStack args(L);
    bool bRet = false;
    if (args[3].IsInteger()) {
        CControlUI* ctrl = (CControlUI*)LuaHelperNS::GetCObjectData(args[2]);
        bRet = CObjPtr->AddAt(ctrl, args[3].GetInteger());
    }
    L->PushBoolean(bRet);
    return 1;
}

int LuaMenu::GetItemIndex(LuaState *L)
{
    LuaStack args(L);
    CControlUI* ctrl = (CControlUI*)LuaHelperNS::GetCObjectData(args[2]);
    int iRet = CObjPtr->GetItemIndex(ctrl);
    L->PushInteger(iRet);
    return 1;
}

int LuaMenu::SetItemIndex(LuaState *L)
{
    LuaStack args(L);
    bool bRet = false;
    if (args[3].IsInteger()) {
        CControlUI* ctrl = (CControlUI*)LuaHelperNS::GetCObjectData(args[2]);
        bRet = CObjPtr->SetItemIndex(ctrl, args[3].GetInteger());
    }
    L->PushBoolean(bRet);
    return 1;
}

int LuaMenu::Remove(LuaState *L)
{
    LuaStack args(L);
    bool bRet = false;
    CControlUI* ctrl = (CControlUI*)LuaHelperNS::GetCObjectData(args[2]);
    bRet = CObjPtr->Remove(ctrl);
    L->PushBoolean(bRet);
    return 1;
}

int LuaMenu::EstimateSize(LuaState *L)
{
    LuaStack args(L);
    SIZE szAvailable = LuaHelperNS::GetSize(args[2]);
    SIZE sz = CObjPtr->EstimateSize(szAvailable);
    LuaHelperNS::PushSize(L, sz);
    return 1;
}

SDLUA_BEGIN_REGISTER(LuaMenu, Menu, List)
    SDLUA_REGISTER_FUN_LUA(LuaMenu, Add, Add)
    SDLUA_REGISTER_FUN_LUA(LuaMenu, AddAt, AddAt)

    SDLUA_REGISTER_FUN_LUA(LuaMenu, GetItemIndex, GetItemIndex)
    SDLUA_REGISTER_FUN_LUA(LuaMenu, SetItemIndex, SetItemIndex)
    SDLUA_REGISTER_FUN_LUA(LuaMenu, Remove, Remove)

    SDLUA_REGISTER_FUN_LUA(LuaMenu, EstimateSize, EstimateSize)
    
SDLUA_END_REGISTER

SDLUA_BEGIN_UNREGISTER(LuaMenu, Menu)
SDLUA_END_UNREGISTER(Menu)

}

#undef CObjPtr